package E2019;

import java.util.HashMap;
import java.util.Iterator;
class BankAccount{
    // 声明变量
    String id;
    String name;
    double money;
    // 构造方法
    public BankAccount(String id, String name, double money) {
        this.id = id;
        this.name = name;
        this.money = money;
    }
    // 重写toString
    @Override
    public String toString() {
        return "储户id：" + id + '\t' + "姓名" + name + '\t' + "余额" + money;
    }
}
public class Exam3 {
    public static void main(String[] args) {
        // 创建HashMap
        HashMap<String,BankAccount> hashMap = new HashMap<>();
        // 添加元素
        hashMap.put("101",new BankAccount("101","祝枝山",10000.0));
        hashMap.put("102",new BankAccount("102","文征明",20000.0));
        hashMap.put("103",new BankAccount("103","唐伯虎",30000.0));
        // 检索目标元素
        if (hashMap.containsKey("102")){
            System.out.println("检索id为102的储户信息如下："+"\n"+hashMap.get("102"));
        }
        // 遍历打印
        System.out.println("遍历哈希表结果如下：");
        Iterator iterator = hashMap.keySet().iterator();
        while (iterator.hasNext()){
            Object key = iterator.next();
            Object value = hashMap.get(key);
            System.out.println(value);
        }
    }
}
